package com.cwz.admin.controller;

import com.alibaba.fastjson.JSON;
import com.cwz.admin.entity.Commodity;
import com.cwz.admin.service.commodity.commodityService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@Configuration
public class commodityController {

    @Autowired
    private commodityService commodityService;

    /**
     * 分页查询商品所有
     * @param commodity 查询条件
     * @return
     */
    @GetMapping("adminFindCommodityByMall")
    public PageInfo adminFindCommodityByMall (Commodity commodity){
        PageInfo list = commodityService.adminFindCommodityByMall(commodity);
        return list;
    }

    /**
     * 商品删除，批量删除或删除单个商品
     * @param commodityIds 删除商品的数组ID
     * @return
     */
    @DeleteMapping("/adminDelCommodityByMall/{commodityIds}")
    public int adminDelCommodityByMall(@PathVariable("commodityIds") int [] commodityIds){
        int i = commodityService.adminDelCommodityByMall(commodityIds);
        return i;
    }

    /**
     * 单个商品的ID查询
     * @param commodityId 商品id
     * @return
     */
    @GetMapping("adminFindCommodityByID/{commodityId}")
    public Commodity adminFindCommodityByID(@PathVariable("commodityId") int commodityId){
        Commodity commodity = commodityService.adminFindCommodityByID(commodityId);
        return commodity;
    }

    /**
     * 修改商品状态
     * @param commodity 商品信息对象
     * @return
     */
    @PutMapping("adminUpdCommodity")
    public int adminUpdCommodity(Commodity commodity){
        int i = commodityService.adminUpdCommodity(commodity);
        return i;
    }



}
